﻿

#region Using Statements

// System References
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;

// XNA References
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

// Internal References
using Freeform.Framework;
using Freeform.Framework.Graphics;
using Game = Freeform.Framework.Game;

#endregion


namespace Freeform.Framework.Menu
{
    /// <summary>
    /// Represents the base class for a simple text based menu item.
    /// </summary>
    public class MenuItem_Image2D : MenuItem
    {

        #region Members

        /// <summary>
        /// Gets the TextActor for this item.
        /// </summary>
        public Actor_Image2D ImageActor { get; private set; }

        #endregion


        #region Initialisation
        /// <summary>
        /// Constructs a Menu Item represented by an Image instead of Text.
        /// </summary>
        /// <param name="World">Which world the entity binds to</param>
        /// <param name="TextureName">The name of a texture used to load an image from the content pipeline</param>
        public MenuItem_Image2D(World World, String TextureName)
            : base(World)
        {
            ImageActor = new Actor_Image2D(this, TextureName);
            Actor = ImageActor;
            Viewport2D View = World.Viewports[0];

            int x = ImageActor.Animations.Current.Texture.Bounds.Width;
            int y = ImageActor.Animations.Current.Texture.Bounds.Height;
            ImageActor.Entity.SpatialProperties.Size = new Vector2(x / (View.RenderTarget.Width / View.Camera.SpatialProperties.Size.X),
                y / (View.RenderTarget.Height / View.Camera.SpatialProperties.Size.Y));
        }

        public MenuItem_Image2D(World World, String TextureName, int TextureWidth, int PausedFrame)
            : base(World)
        {
            ImageActor = new Actor_Image2D(this, TextureName);
            Actor = ImageActor;
            Viewport2D View = World.Viewports[0];

            int x = ImageActor.Animations.Current.Texture.Bounds.Width;
            int y = ImageActor.Animations.Current.Texture.Bounds.Height;
            ImageActor.Entity.SpatialProperties.Size = new Vector2(x / (View.RenderTarget.Width / View.Camera.SpatialProperties.Size.X),
                y / (View.RenderTarget.Height / View.Camera.SpatialProperties.Size.Y));

            ImageActor.Animations.AddAnimation((new Animation(TextureName, "Tex", 1, x / TextureWidth, 1)));
            ImageActor.Animations.PlayAnimation("Tex");
            ImageActor.Animations.Current.FreezeOnFrame(PausedFrame);
            ImageActor.Animations.RemoveAnimation("Default");
        }
        #endregion

    }
}